<?php

class Visitor_model extends Model{

	var $table_name = 'visitor';
	
	function Visitor_model()
	{
		parent::Model();
	}
	
	function get_count()
	{
		$this->db->select('*');	
		$query = $this->db->get($this->table_name);	
		return $query->num_rows();		
	}
	
	function cekIp()
	{
		$ip = $this->input->ip_address();
		$now =  date('Y-m-d');
		
		$this->db->select('*');	
		$this->db->where('ip_address', $ip);	
		$this->db->like('created_date', $now);
		
		$query = $this->db->get($this->table_name);	
		$count = $query->num_rows();
		
		if($count <= 0){
			return $this->addVisitor();
		}else{
			return $count;	
		}
	}
	
	function addVisitor()
	{	
		$ip = $this->input->ip_address();
		
		$data = array(
			'ip_address' => $ip,
			'created_date' => date('Y-m-d h:i:s'),
		);
		
		$query =  $this->db->insert($this->table_name, $data); 
		return $query;
	
	}
	
}

/* End of file visitor_model.php */
/* Location: ./apps/models/visitor_model.php */	
?>